package com.CollectionJiHe.CollectionAPI;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

public class CollectionTest {
    public static void main(String[] args) {
        Collection<String>c=new ArrayList<>();
        //添加元素，添加成功返回true   //public boolean add(E e);
        c.add("java1");
        c.add("java1");
        c.add("java2");
        c.add("java2");
        c.add("java3");
        System.out.println(c);
        //清空集合中的元素
//        c.clear();
//        System.out.println(c);
        //判断集合是否为空，时空的话返回true
        System.out.println(c.isEmpty());
        //获取集合的大小
        System.out.println(c.size());
        //判断集合中是否包含某个元素
        System.out.println(c.contains("java2"));
        //删除某个元素默认是删除第一个
        System.out.println(c.remove("java1"));
        //将集合转化为数组
        Object[] arr = c.toArray();
        System.out.println(Arrays.toString(arr));
        String[]arr2=c.toArray(new String[0]);
        System.out.println(Arrays.toString(arr2));
        System.out.println("--------------------");
        Collection<String>c1=new ArrayList<>();
        c1.add("java1");
        c1.add("java2");
        Collection<String>c2=new ArrayList<>();
        c2.add("java3");
        c2.add("java4");
        c1.addAll(c2);
        System.out.println(c1);
        System.out.println(c2);

    }
}
